#pragma once

// -----------------------------------------------------------------------------

#include <Winerror.h>
#include <Windows.h>
#include <Winbase.h>

namespace Kif
{
namespace Win32
{

class String;

namespace Diagnostics
{

class Result
{
public:

   long    LocalErrorNo;
   DWORD   ErrorNo;
   HRESULT HResult;

   void Clear()
   {
      ErrorNo = 0;
      LocalErrorNo = 0;
      HResult = S_OK;
   }

   Result()
   {
      Clear();
   }  // end of Result (ctor)

   bool Success()
   {
      return(((ErrorNo == 0) && (HResult == S_OK) && (LocalErrorNo == 0)));
   }  // end of Success

   Kif::Win32::String *GetErrorMessage();
   void ErrorNumsToString(Kif::Win32::String &message);

}  ;

/// <summary>Result Object provides to store an object of a given type
/// </summary>
template <typename T>
class ResultObject
{
private:
   T m_Object;

public:

   T *GetObjectPointer()
   {
      return &m_Object;
   }

   long    LocalErrorNo;
   DWORD   ErrorNo;
   HRESULT HResult;

   void Clear()
   {
      ErrorNo = 0;
      LocalErrorNo = 0;
      HResult = S_OK;
   }

   ResultObject()
   {
      Clear();
   }  // end of Result (ctor)

   bool Success()
   {
      return(((ErrorNo == 0) && (HResult == S_OK) && (LocalErrorNo == 0)));
   }  // end of Success

   Kif::Win32::String *GetErrorMessage();
   void ErrorNumsToString(Kif::Win32::String &message);

}  ;  // end of ResultObject

}  // end of Kif::Win32::Diagnostics
}  // end of Kif::Win32
}  // end of Kif

